#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e4 + 5;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], W[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int d, cnt;
int mx[N];
void dfs(int u, int fu) {
  mx[u] = 0;
  vector<int> a;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
    int now = W[i] + mx[v];
    if (now >= d)
      cnt++;
    else
      a.push_back(now);
  }
  // 以下使用贪心进行配对
  sort(a.begin(), a.end());
  int l = 0, r = a.size() - 1;
  vector<int> b;
  vector<pii> c;
  while (l < r) {
    if (a[l] + a[r] < d) {
      b.push_back(a[l++]);
    } else {
      c.push_back(pii(a[l++], a[r--]));
      cnt++;
    }
  }
  // 以下使用反悔保留最大链
  if (l == r) b.push_back(a[l]);
  if (b.size()) {
    int x = b.back();
    for (auto it = c.rbegin(); it != c.rend(); it++) {
      int y = it->first, z = it->second;
      if (x + y >= d)
        x = z;
      else
        break;
    }
    mx[u] = x;
  }
  // 看了其他人使用了multiset直接进行贪心
}
bool check(int x) {
  d = x, cnt = 0;
  dfs(1, 1);
  return cnt >= m;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  int l = 1, r = 5e8;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r;
  return 0;
}